{
  "properties" : { },
  "id" : "8341d2324ce543419684d021abdc9cd3",
  "script" : null,
  "groupId" : "8072991b1c194fb08fdf8da03cd8c54b",
  "name" : "巡检任务执行",
  "createTime" : 1727071087267,
  "updateTime" : 1726628965520,
  "lock" : "0",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "auditCheck",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\"id\":\"1830529790264872960\"}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 500,\n    \"success\": false,\n    \"data\": {},\n    \"msg\": \"系统维护中，请稍后重试。\"\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : null,
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "500",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "success",
      "value" : "false",
      "description" : "",
      "required" : false,
      "dataType" : "Boolean",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "msg",
      "value" : "系统维护中，请稍后重试。",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
 import java.time.LocalDateTime;
 import java.sql.Timestamp;
 import com.kd.ndmp.util.DateUtil;
 import java.util.stream.Collectors;
 import org.springframework.web.reactive.function.client.WebClient;
 import reactor.core.publisher.Mono;
 import org.springframework.http.HttpMethod;
 import redis;


 import "@/util/getAuditRuleByExpression" as getAuditRuleByExpression;


 String OSPF = "ospf";
 String LOOP_BACK0 = "loopback0";
 String NET_MASK = "255.255.255.252";


 LocalDateTime now = LocalDateTime.now();
 //  巡检范围，设备id
 List rangeList = db.table("ndmp_audit_range").where().eq("task_id", id).select();
 var task = db.table("ndmp_audit_task").where().eq("id", id).selectOne();
 if (task == null) {
     throw new RuntimeException("没有该巡检计划");
 }
 Timestamp nowTime = new Timestamp(System.currentTimeMillis());
 task.put("execTime", task.get("taskExecuteTime"));
 task.put("TaskExecuteTime", nowTime);
 Integer taskTimeFrame = task.get("taskTimeFrame")::int;
 Timestamp next;
 if (taskTimeFrame == null) {
     taskTimeFrame = 1;
 }
 if (taskTimeFrame == 1) { // 年为周期
     next = new Timestamp(DateUtil.getNextYear(new Date(nowTime.getTime()), 1).getTime());
 } else if (taskTimeFrame == 2) { // 季度为周期
     next = new Timestamp(DateUtil.getNextMonth(new Date(nowTime.getTime()), 3).getTime());
 } else { // 月为周期
     next = new Timestamp(DateUtil.getNextMonth(new Date(nowTime.getTime()), 1).getTime());
 }
 task.put("taskExecuteNextTime", next);
 db.table("ndmp_audit_task").update(task);

 List taskRuleList = db.select("""
 
    SELECT
            *
        FROM
            ndmp_audit_rule
        WHERE
                ID IN ( SELECT rule_id FROM ndmp_audit_task_rule WHERE task_id = #{taskId} )
""")
 List resultList = new ArrayList();
 List expressionList = taskRuleList.stream().map(v -> v.get("expression")).collect(Collectors.toList());
 if (expressionList.contains("serviceCpu") || expressionList.contains("serviceMemory") || expressionList.contains("serviceDisk")) {

     var auditRuleServiceCpu = getAuditRuleByExpression("serviceCpu", taskRuleList);
     var auditRuleServiceMemory = getAuditRuleByExpression("serviceMemory", taskRuleList);
     var auditRuleServiceDisk = getAuditRuleByExpression("serviceDisk", taskRuleList);
     Set serviceIpList = ipMap.keySet();

     for (serviceIp in serviceIpList) {
         //cpu
         String cpuUrl = "http://" + serviceIp + ":28080/gather/hardWare/getCpuInfo";
         Mono < CpuInfo > responseCpu = WebClient.create().method(HttpMethod.GET).uri(cpuUrl)
             .retrieve().bodyToMono(CpuInfo.class);

         CpuInfo cpuInfo = responseCpu.block();
         log.info("cpuInfo is :{}", cpuInfo);
         var resultCpu ={
         taskId:(taskId),
         deviceId:(serviceIp),
         updateTime:(now),
         ruleId:(auditRuleServiceCpu.id),
         result:(JSONObject.toJSONString(cpuInfo))
            }
         resultList.add(resultCpu);

         //内存
         String memoryUrl = "http://" + serviceIp + ":28080/gather/hardWare/getMemoryInfo";
         Mono < MemoryInfo > responseMemory = WebClient.create().method(HttpMethod.GET).uri(memoryUrl)
             .retrieve().bodyToMono(MemoryInfo.class);

         MemoryInfo memoryInfo = responseMemory.block();
         log.info("memoryInfo is :{}", memoryInfo);

         var resultMemory = {
         taskId:(taskId),
         deviceId:(serviceIp),
         updateTime:(now),
         ruleId:(auditRuleServiceMemory.id),
         result:(JSONObject.toJSONString(memoryInfo))
        }
         resultList.add(resultMemory);


         //磁盘
         String diskUrl = "http://" + serviceIp + ":28080/gather/hardWare/getDiskInfo";
         Mono < List > responseDevice = WebClient.create().method(HttpMethod.GET).uri(diskUrl)
             .retrieve().bodyToMono(List.class);
         List diskInfoList = responseDevice.block();
         log.info("diskInfo is :{}", diskInfoList);

         AuditResultEntity resultDisk = {
         taskId:(taskId),
         deviceId:(serviceIp),
         updateTime:(now),
         ruleId:(auditRuleServiceDisk.id),
         result:(JSONObject.toJSONString(diskInfoList))
        }
         resultList.add(resultDisk);
     }


 } else {
     if (!rangeList.isEmpty() && !taskRuleList.isEmpty()) {
         //从检查规则中筛选出 OSPF 规则
         var auditRuleOspf = getAuditRuleByExpression(OSPF, taskRuleList);
         //从检查规则中筛选出 LOOP_BACK0 规则
         var auditRuleLoopBack = getAuditRuleByExpression(LOOP_BACK0, taskRuleList);

         //从检查规则中筛选出 设备cpu规则
         var auditRuleDeviceCpu = getAuditRuleByExpression("deviceCpu", taskRuleList);
         var auditRuleDeviceMemory = getAuditRuleByExpression("deviceMemory", taskRuleList);
         var auditRuleDeviceDelay = getAuditRuleByExpression("deviceDelay", taskRuleList);
         var auditRuleDevicePacketLoss = getAuditRuleByExpression("devicePacketLoss", taskRuleList);


         for (rangeEntity in rangeList) {
             String deviceId = rangeEntity.deviceId;

             if (null != auditRuleOspf) {

                 taskRuleList = taskRuleList.stream().filter(v -> {
                     String expression = v.getExpression();
                     if (expression != null) {
                         return !expression.equals(OSPF);
                     } else {
                         return false;
                     }
                 }).collect(Collectors.toList());
                 //查询开通的协议
                 PointObject pointObject = StringRedisTemplateUtil.getPoint(deviceId, "ipRouteProto");
                 //查询子网掩码 是否为30位  255.255.255.252
                 PointObject pointObjectMark = StringRedisTemplateUtil.getPoint(deviceId, "ipRouteMask");

                 NdmpDevice ndmpNetDevice = db.table("ndmp_device").where().eq("id", deviceId).selectOne();

                 String openService = "";
                 String netMask = "";
                 if (pointObject != null) {
                     openService = pointObject.getValue().get("0");
                 }
                 if (pointObjectMark != null) {
                     netMask = pointObjectMark.getValue().get(ndmpNetDevice.ip);
                 }
                 //获取对应ip的子网掩码
                 var resultEntity = new AuditResultEntity();
                 resultEntity.taskId=(taskId);
                 resultEntity.deviceId=(rangeEntity.deviceId);
                 resultEntity.updateTime=(now);
                 resultEntity.ruleId=(auditRuleOspf.id);

                 if (!StringUtils.isEmpty(openService) && !StringUtils.isEmpty(netMask) && openService.contains(OSPF) && netMask.equals(NET_MASK)) {
                     resultEntity.result=("1");
                 }
                 resultList.add(resultEntity);
             }

             //检查接口名称
             if (null != auditRuleLoopBack) {
                 taskRuleList = taskRuleList.stream().filter(v -> {
                     String expression = v.expression;
                     if (expression != null) {
                         return !expression
                             .equals(LOOP_BACK0);
                     } else {
                         return false;
                     }
                 }).collect(Collectors.toList());
                 PointObject pointObject = StringRedisTemplateUtil.getPoint(deviceId, "ifDescr");
                 if (null != pointObject) {

                     List ifDescrList = new ArrayList();
                     AuditResultEntity resultEntity = new AuditResultEntity();
                     resultEntity.setTaskId(taskId);
                     resultEntity.setDeviceId(rangeEntity.getDeviceId());
                     resultEntity.setUpdateTime(now);
                     resultEntity.setRuleId(auditRuleLoopBack.getId());
                     List ifDescrLowerCaseList =
                         ifDescrList.stream().map(String::toLowerCase).collect(Collectors.toList());

                     if (ifDescrLowerCaseList.contains(LOOP_BACK0)) {
                         resultEntity.setResult("1");
                     }
                     resultList.add(resultEntity);
                 }
             }

             if (null != auditRuleDeviceCpu) {

                 taskRuleList = taskRuleList.stream().filter(v -> {
                     String expression = v.getExpression();
                     if (expression != null) {
                         return !"deviceCpu".equals(expression);
                     } else {
                         return false;
                     }
                 }).collect(Collectors.toList());
                 //查询cpu使用率
                 PointObject pointObject = StringRedisTemplateUtil.getPoint(deviceId, "cpuUsage");
                 String cpuUsage = "";
                 if (pointObject != null) {
                     cpuUsage = pointObject.getValue().get("0");
                 }

                 AuditResultEntity resultEntity = new AuditResultEntity();
                 resultEntity.setTaskId(taskId);
                 resultEntity.setDeviceId(rangeEntity.getDeviceId());
                 resultEntity.setUpdateTime(now);
                 resultEntity.setRuleId(auditRuleDeviceCpu.getId());
                 resultEntity.setResult(Objects.equals(cpuUsage, "") ? "" : cpuUsage + "%");

                 resultList.add(resultEntity);
             }
             if (null != auditRuleDeviceMemory) {

                 taskRuleList = taskRuleList.stream().filter(v -> {
                     String expression = v.getExpression();
                     if (expression != null) {
                         return !"deviceMemory".equals(expression);
                     } else {
                         return false;
                     }
                 }).collect(Collectors.toList());
                 //查询cpu使用率
                 PointObject pointObject = StringRedisTemplateUtil.getPoint(deviceId, "memUsage");
                 String memUsage = "";
                 if (pointObject != null) {
                     memUsage = pointObject.getValue().get("0");
                 }

                 AuditResultEntity resultEntity = new AuditResultEntity();
                 resultEntity.setTaskId(taskId);
                 resultEntity.setDeviceId(rangeEntity.getDeviceId());
                 resultEntity.setUpdateTime(now);
                 resultEntity.setRuleId(auditRuleDeviceMemory.getId());
                 resultEntity.setResult(Objects.equals(memUsage, "") ? "" : memUsage + "%");

                 resultList.add(resultEntity);
             }
             if (null != auditRuleDeviceDelay) {

                 taskRuleList = taskRuleList.stream().filter(v -> {
                     String expression = v.getExpression();
                     if (expression != null) {
                         return !"delayTime".equals(expression);
                     } else {
                         return false;
                     }
                 }).collect(Collectors.toList());
                 //查询cpu使用率
                 PointObject pointObject = StringRedisTemplateUtil.getPoint(deviceId, "delayTime");
                 String memUsage = "";
                 if (pointObject != null) {
                     memUsage = pointObject.getValue().get("0");
                 }

                 AuditResultEntity resultEntity = new AuditResultEntity();
                 resultEntity.setTaskId(taskId);
                 resultEntity.setDeviceId(rangeEntity.getDeviceId());
                 resultEntity.setUpdateTime(now);
                 resultEntity.setRuleId(auditRuleDeviceDelay.getId());
                 resultEntity.setResult(memUsage);

                 resultList.add(resultEntity);
             }
             if (null != auditRuleDevicePacketLoss) {

                 taskRuleList = taskRuleList.stream().filter(v -> {
                     String expression = v.getExpression();
                     if (expression != null) {
                         return !"devicePacketLoss".equals(expression);
                     } else {
                         return false;
                     }
                 }).collect(Collectors.toList());
                 //查询cpu使用率
                 PointObject pointObject = StringRedisTemplateUtil.getPoint(deviceId, "packetLoss");
                 String packetLoss = "";
                 if (pointObject != null) {
                     packetLoss = pointObject.getValue().get("0");
                 }

                 AuditResultEntity resultEntity = new AuditResultEntity();
                 resultEntity.setTaskId(taskId);
                 resultEntity.setDeviceId(rangeEntity.getDeviceId());
                 resultEntity.setUpdateTime(now);
                 resultEntity.setRuleId(auditRuleDevicePacketLoss.getId());
                 resultEntity.setResult(packetLoss);

                 resultList.add(resultEntity);
             }
             //  获取配置文件
             NetDeviceCfgFile netDeviceCfgFile = db.table("ndmp_net_device_cfg_file").where().eq("device_id", deviceId).orderByDesc("UPDATE_TIME").selectOne();

             if (netDeviceCfgFile == null) {
                 continue;
             }
             var bytes = netDeviceCfgFile.getFile();
             String file = new String(bytes);
             if (StringUtils.isNotBlank(file)) {

                 for (rule in taskRuleList) {
                     var resultEntity = new AuditResultEntity();
                     resultEntity.taskId = (taskId);
                     resultEntity.deviceId = (rangeEntity.deviceId);
                     resultEntity.updateTime = (now);
                     resultEntity.ruleId = (rule.id);

                     if (isValid(file, rule.getExpression())) {
                         resultEntity.setResult("1");
                     }
                     resultList.add(resultEntity);
                 }

             }
         }
     }
 }
 if (!resultList.isEmpty()) {
     return saveBatch(resultList);
 }
 return false;